﻿/******************************************************************************
 * Copyright 2020-xxxx xxx Co., Ltd.
 * All right reserved. See COPYRIGHT for detailed Information.
 *
 * @projectName   aaa
 * @file          xcustombar.h
 * @brief         XCustomBar class
 *
 * @author        Feng<2859352492@qq.com>
 * @date          2022/03/12 15:03:29
 * @history
 *****************************************************************************/

#ifndef XCUSTOMBARS_H
#define XCUSTOMBARS_H

#include <QObject>
#include "objlib.h"
#include "basedata.h"
#include "qcustomplot.h"
#include "xnamespace.h"
#include "xcustomchartlist.h"

QT_BEGIN_NAMESPACE

using namespace xvs;

class XCustomBarPrivate;
class XCustomBar : public QCPBars
{
public:
    explicit XCustomBar(QCustomPlot *parent = nullptr);
    ~XCustomBar();

    // getters
    //appearance
    QColor penColor() const;
    QColor brushColor() const;
    //text
    ChartValueTextPosition textPosition() const;
    double textOffset() const;
    QFont textFont() const;
    QColor textColor() const;

    // setters
    //data
    void setValue(Array &array);                            //Array内需为Integer/Real
    //appearance
    void setPenColor(const QColor &color);
    void setBrushColor(const QColor &color);
    //text
    void setTextPosition(ChartValueTextPosition position);
    void setTextOffset(double offset);
    void setTextFont(const QFont &font);
    void setTextColor(const QColor &color);

protected:
    //update
    void updateDataRange();

    // reimplemented virtual methods:
    virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;

    // introduced virtual methods:
    virtual void drawValueText(QCPPainter *painter, QCPBarsDataContainer::const_iterator it, const QRectF &barRect) const;

private:
    XCustomBarPrivate *XCustomBarP = nullptr;
};


class XCustomBarsPrivate;
class XCustomBars : public QObject
{
    Q_OBJECT
public:
    explicit XCustomBars(QCustomPlot *parent = nullptr);
    ~XCustomBars();

    // object list
    XCustomChartList<XCustomBar*> *barList = nullptr;

    // getters
    //object
    BarsPlaceStrategy placeStrategy() const;
    double barOffset() const;

    // setters
    //object
    void setPlaceStrategy(BarsPlaceStrategy);
    void setBarOffset(double offset);

    // adjust
    void adjustBars();

protected:
    void setAdjacentBars();
    void setStackBars();

private:
    Q_DISABLE_COPY(XCustomBars)
    QCustomPlot *customBarsParent = nullptr;
    QCPBarsGroup *mBarsGroup = nullptr;           //组对象指针
    XCustomBarsPrivate *XCustomBarsP = nullptr;
};

QT_END_NAMESPACE

#endif // XCUSTOMBARS_H
